package learn.Thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;


/*
* Question A：有100个任务需要分成10批执行，每批执行有顺序（即第一批执行完执行第二批）。
● 说明：10批任务有序执行，每批任务的10个任务要做到并发执行
● 加分项：如果可以，写出多种不同原理或不同工具的实现方式
* */

public class test13 {
    public static void main(String[] args) {
        //CountDownLatch count = new CountDownLatch(10);
        CyclicBarrier count = new CyclicBarrier(10);
        for (int i = 0; i < 10; i++) {
            t1 t1 = new t1(count);
            t1.start();
        }
    }
}

class t1 extends Thread{
    private static CyclicBarrier count;
    public t1(CyclicBarrier count){
        this.count = count;
    }
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("第"+i+"批任务"+Thread.currentThread().getName());
            try {
                count.await();
            } catch (InterruptedException | BrokenBarrierException e) {
                e.printStackTrace();
            }
        }

    }
}
